//package com.blt.car.psuh;
//
//import android.app.Notification;
//import android.app.NotificationManager;
//import android.app.PendingIntent;
//import android.app.Service;
//import android.content.Context;
//import android.content.Intent;
//import android.graphics.Bitmap;
//import android.graphics.BitmapFactory;
//import android.os.IBinder;
//import android.util.Log;
//
//import com.blt.car.MainActivity;
//import com.blt.car.R;
//import com.umeng.message.UTrack;
//import com.umeng.message.entity.UMessage;
//
//import org.json.JSONException;
//import org.json.JSONObject;
//
//import java.util.Random;
//
///**
// * Created by mitic_xue on 16/10/28.
// */
//public class MyNotificationService extends Service {
//    private static final String TAG = UmengNotificationService.class.getName();
//    public static UMessage oldMessage = null;
//
//    @Override
//    public void onCreate() {
//        super.onCreate();
//    }
//
//    @Override
//    public int onStartCommand(Intent intent, int flags, int startId) {
//        String message = intent.getStringExtra("UmengMsg");
//        try {
//            UMessage msg = new UMessage(new JSONObject(message));
//            if (oldMessage != null) {
//                UTrack.getInstance(getApplicationContext()).setClearPrevMessage(true);
//                UTrack.getInstance(getApplicationContext()).trackMsgDismissed(oldMessage);
//            }
//            showNotification(msg);
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
//        return super.onStartCommand(intent, flags, startId);
//    }
//
//    private void showNotification(UMessage msg) {
//        int id = new Random(System.nanoTime()).nextInt();
//        oldMessage = msg;
//        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//        manager.cancelAll();
//
//        Notification.Builder mBuilder = new Notification.Builder(this);
//        mBuilder.setContentTitle(msg.title)
//                .setContentText(msg.text)
//                .setTicker(msg.ticker)
//                .setWhen(System.currentTimeMillis())
//                .setSmallIcon(R.mipmap.logo)
//                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.logo))
//                .setAutoCancel(true);
//
//
//        Log.d("MyNotificationService", "showNotification");
//
//        Notification notification = mBuilder.build();
//        PendingIntent clickPendingIntent = getClickPendingIntent(this, msg);
//        PendingIntent dismissPendingIntent = getDismissPendingIntent(this, msg);
//        notification.deleteIntent = dismissPendingIntent;
//        notification.contentIntent = clickPendingIntent;
//        manager.notify(id, notification);
//    }
//
//    public PendingIntent getClickPendingIntent(Context context, UMessage msg) {
//        Intent intent = new Intent(context,MainActivity.class);
//        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
//        return  pendingIntent;
//
////        Intent clickIntent = new Intent();
////        clickIntent.setClass(context, NotificationBroadcast.class);
////        clickIntent.putExtra(NotificationBroadcast.EXTRA_KEY_MSG,
////                msg.getRaw().toString());
////        clickIntent.putExtra(NotificationBroadcast.EXTRA_KEY_ACTION,
////                NotificationBroadcast.ACTION_CLICK);
////        PendingIntent clickPendingIntent = PendingIntent.getBroadcast(context,
////                (int) (System.currentTimeMillis()),
////                clickIntent, PendingIntent.FLAG_CANCEL_CURRENT);
//
////        return clickPendingIntent;
//    }
//
//    public PendingIntent getDismissPendingIntent(Context context, UMessage msg) {
//        Intent deleteIntent = new Intent();
//        deleteIntent.setClass(context, NotificationBroadcast.class);
//        deleteIntent.putExtra(NotificationBroadcast.EXTRA_KEY_MSG,
//                msg.getRaw().toString());
//        deleteIntent.putExtra(
//                NotificationBroadcast.EXTRA_KEY_ACTION,
//                NotificationBroadcast.ACTION_DISMISS);
//        PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context,
//                (int) (System.currentTimeMillis() + 1),
//                deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT);
//        return deletePendingIntent;
//    }
//
//    @Override
//    public IBinder onBind(Intent intent) {
//        return null;
//    }
//}
